package com.haixiaoke.service.impl;

import java.util.List;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.haixiaoke.common.utils.DateUtils;
import com.haixiaoke.common.utils.RandomNoUtils;
import com.haixiaoke.common.utils.StringUtils;
import com.haixiaoke.domain.SmartLock;
import com.haixiaoke.domain.SmartLockPwd;
import com.haixiaoke.mapper.SmartLockPwdMapper;
import com.haixiaoke.service.ISmartLockPwdService;
import com.haixiaoke.smartLock.tianwanghulian.SmartLockTWHlService;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 智能锁密码授权信息Service业务层处理
 *
 * @author xiaolong
 * @date 2023-05-31
 */
@Service
public class SmartLockPwdServiceImpl implements ISmartLockPwdService {
    @Autowired
    private SmartLockPwdMapper smartLockPwdMapper;
    @Autowired
    private SmartLockTWHlService smartLockTWHlService;

    /**
     * 查询智能锁密码授权信息
     *
     * @param pwdId 智能锁密码授权信息主键
     * @return 智能锁密码授权信息
     */
    @Override
    public SmartLockPwd selectSmartLockPwdByPwdId(Long pwdId) {
        return smartLockPwdMapper.selectSmartLockPwdByPwdId(pwdId);
    }

    /**
     * 查询智能锁密码授权信息列表
     *
     * @param smartLockPwd 智能锁密码授权信息
     * @return 智能锁密码授权信息
     */
    @Override
    public List<SmartLockPwd> selectSmartLockPwdList(SmartLockPwd smartLockPwd) {
        return smartLockPwdMapper.selectSmartLockPwdList(smartLockPwd);
    }

    /**
     * 新增智能锁密码授权信息和智能锁密码授权
     *
     * @param smartLockPwd 智能锁密码授权信息
     * @return 结果
     */
    @Override
    public int insertSmartLockPwd(SmartLockPwd smartLockPwd) {
        smartLockPwd.setCreateTime(DateUtils.getNowDate());
        return smartLockPwdMapper.insertSmartLockPwd(smartLockPwd);
    }

    /**
     * 修改智能锁密码授权信息
     *
     * @param smartLockPwd 智能锁密码授权信息
     * @return 结果
     */
    @Override
    public int updateSmartLockPwd(SmartLockPwd smartLockPwd) {
        smartLockPwd.setUpdateTime(DateUtils.getNowDate());
        return smartLockPwdMapper.updateSmartLockPwd(smartLockPwd);
    }

    /**
     * 批量删除智能锁密码授权信息
     *
     * @param pwdIds 需要删除的智能锁密码授权信息主键
     * @return 结果
     */
    @Override
    public int deleteSmartLockPwdByPwdIds(Long[] pwdIds) {
        return smartLockPwdMapper.deleteSmartLockPwdByPwdIds(pwdIds);
    }

    /**
     * 删除智能锁密码授权信息信息
     *
     * @param pwdId 智能锁密码授权信息主键
     * @return 结果
     */
    @Override
    public int deleteSmartLockPwdByPwdId(Long pwdId) {
        return smartLockPwdMapper.deleteSmartLockPwdByPwdId(pwdId);
    }

    /**
     * 删除智能锁密码授权信息和删除密码授权
     * @param sn 智能锁sn
     * @param identification 天网互联智能锁标识
     * @return
     */
    @Override
    public int deleteSmartLockPwdBySnAndIdentification(String sn, String identification) {
        return smartLockPwdMapper.deleteSmartLockPwdBySnAndIdentification(sn,identification);
    }

    @Override
    public List<SmartLockPwd> selectSmartLockPwdBySN(String sn) {
        SmartLockPwd pwd = new SmartLockPwd();
        pwd.setSn(sn);
        return smartLockPwdMapper.selectSmartLockPwdList(pwd);
    }

    @Override
    public int deleteSmartLockPwdByReturnPwdId(Long returnPwdId) {
        return smartLockPwdMapper.deleteSmartLockPwdByReturnPwdId(returnPwdId);
    }

    @Override
    public SmartLockPwd selectSmartLockPwdBySNAndIdentification(String sn, String identification) {
        return smartLockPwdMapper.selectSmartLockPwdBySNAndIdentification(sn,identification);
    }

    public int deleteSmartLockPwdBySn(String sn) {
        return smartLockPwdMapper.deleteSmartLockPwdBySn(sn);
    }

    public int deleteSmartLockPwdByEndTime(DateTime date) {
        return smartLockPwdMapper.deleteSmartLockPwdByEndTime(date);
    }
}
